#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;

using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;
using System.Collections;
using Gizmox.WebGUI.Common.Resources;
using TVC.Layout;
using System.Xml;
using System.IO;

#endregion

namespace TVC.Modules.Com
{
    public partial class TASK : ModuleParent, IHostedApplication
    {
        //int idAllowEditLanguage = 1;
        //int idAddNew = 1;
        //int idEdit = 1;
        //int idDelete = 1;
        //int idTransferIn = 1;
        //int idTransferOut = 1;
        //int idPrint = 1;
        GridLayout layout = null;

        public TASK()
        {
            InitializeComponent();
            _dgvList = dgvEmployee;
            _strType = "TASK";
        }

        public void InitializeApplication()
        {
        }

        //public void AddNew()
        //{

        //}

        public void SetObject(object obj)
        {
        }

        public HostedToolBarElement[] GetToolBarElements()
        {
            ArrayList objElements = new ArrayList();
            //if (IsPermis(idAddNew))
            //    objElements.Add(new HostedToolBarButton("Add New", new IconResourceHandle("Add.png"), "C"));
            //if (IsPermis(idEdit))
            //    objElements.Add(new HostedToolBarButton("Edit", new IconResourceHandle("Edit.png"), "A"));
            //if (IsPermis(idAddNew) && IsPermis(idEdit))
            //    objElements.Add(new HostedToolBarButton("Save", new IconResourceHandle("Save.png"), "S"));
            //if (IsPermis(idAddNew))
            //    objElements.Add(new HostedToolBarButton("Copy", new IconResourceHandle("Copy.png"), "O"));
            //if (IsPermis(idDelete))
            //    objElements.Add(new HostedToolBarButton("Delete", new IconResourceHandle("Delete.png"), "X"));
            //objElements.Add(new HostedToolBarSeperator());
            //if (IsPermis(idTransferIn))
            //    objElements.Add(new HostedToolBarButton("Transfer In", new IconResourceHandle("Down.png"), "TI"));
            //if (IsPermis(idTransferOut))
            //    objElements.Add(new HostedToolBarButton("Transfer Out", new IconResourceHandle("Up.png"), "TO"));
            //objElements.Add(new HostedToolBarSeperator());
            //if (IsPermis(idPrint))
            //    objElements.Add(new HostedToolBarButton("Print", new IconResourceHandle("Print.png"), "P"));
            objElements.Add(new HostedToolBarButton("Send Mail", "Send Mail", new IconResourceHandle("ClosedMail.png"), "E"));
            objElements.Add(new HostedToolBarButton("Refresh", new IconResourceHandle("Refresh.png"), "R"));

            return (HostedToolBarElement[])objElements.ToArray(typeof(HostedToolBarElement));
        }

        public void OnToolBarButtonClick(HostedToolBarButton objButton, EventArgs objEvent)
        {
            try
            {
                sErr = "";
                string strAction = (string)objButton.Tag;


                switch (strAction)
                {
                    case "E":
                        sendMail();
                        break;
                }
                _processStatus = strAction;
                if (sErr == "") ThrowMsg("Command: " + _processStatus);
            }
            catch (Exception ex)
            {
                ThrowMsg(ex.Message + Environment.NewLine + ex.Source);
            }
        }

        private void sendMail()
        {
            if (_dgvList == null) return;

            if (_dgvList.DataSource is BindingSource)
            {
                if (((BindingSource)_dgvList.DataSource).DataSource == null) return;
            }
            object info = null;
            if (_dgvList.CurrentRow != null && _dgvList.CurrentRow.DataBoundItem != null) info = _dgvList.CurrentRow.DataBoundItem;

            if (info is DataRowView)
            {
                DTO.LIST_TASKInfo inf = new DTO.LIST_TASKInfo((DataRowView)info);
                BUS.LIST_TASKControl ctr = new BUS.LIST_TASKControl();
                if (ctr.IsExist(GetMainForm().DB, inf.Code))
                {
                    frmTestMail frm = new frmTestMail(GetMainForm(), inf);
                    frm.ShowDialog();
                }
            }



        }

        private void Employee_Load(object sender, EventArgs e)
        {
            if (!GetMainForm().IsContainsTables(_strType)) GetMainForm().LoadDataTable(_strType);

            Rebind();
            layout = new GridLayout(MainForm.ServerPath + "Resources\\Layout\\", MainForm.ServerPath + "Documents\\Layout\\" + GetMainForm().PODInfo.USER_ID + "\\", _strType);
            layout.SetUpDGV(dgvEmployee);
            if (dgvEmployee.ShowFilterRow == true)
                mnuShowFilter.Checked = true;
        }
        private void Rebind()
        {
            bisEmployee.DataSource = GetMainForm().GetTable(_strType);
        }
    }
}